from django.db import models

# Create your models here.
# 会员模型
class Users(models.Model):
    username = models.CharField(max_length=30)
    password = models.CharField(max_length=80)
    phone = models.CharField(max_length=11)
    email = models.CharField(max_length=100,null=True)
    sex = models.IntegerField(null=True)
    age = models.IntegerField(null=True)
    pic = models.CharField(max_length=100)
    #状态  0正常 1禁用  2删除
    status = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

    # 指定生成权限
    class Meta:
        permissions = (

            ("show_users", "查看会员管理"),
            ("insert_users", "添加会员"),
            ("edit_users", "修改会员"),
            ("del_users","删除会员")
        )
# 分类模型
class Types(models.Model):
    name = models.CharField(max_length=10)
    pid = models.IntegerField()
    path = models.CharField(max_length=50)

    # 指定生成权限
    class Meta:
        permissions = (
            ("show_types", "查看分类管理"),
            ("insert_types", "添加分类"),
            ("edit_types", "修改分类"),
            ("del_types", "删除分类")
        )

# 商品模型
class Goods(models.Model):
    # 与分类关联外键  1 对  多
    tid = models.ForeignKey(to="Types",to_field="id")
    # 商品标题
    title = models.CharField(max_length=255)
    # 商品价格
    price = models.FloatField()
    # 商品库存
    num = models.IntegerField()
    # 商品详情介绍
    info = models.TextField()
    #  商品图片
    pic = models.CharField(max_length=100)
    # 商品状态 0 新发布   1 热卖  2 上架  3 下架
    status = models.IntegerField(default=0)
    # 点击量
    clicknum = models.IntegerField(default=0)
    # 添加时间
    addtime = models.DateTimeField(auto_now_add=True)

    # 指定生成权限
    class Meta:
        permissions = (
            ("show_goods", "查看商品管理"),
            ("insert_goods", "添加商品"),
            ("edit_goods", "修改商品"),
            ("del_goods", "删除商品")
        )


# 地址模型
class Address(models.Model):
    # 与用户相关联的 外键
    uid = models.ForeignKey(to="Users", to_field="id")
    # 收货人
    addressname = models.CharField(max_length=20)
    # 收货地址
    address = models.CharField(max_length=100)
    # 联系电话
    addressphone = models.CharField(max_length=11)
    # 0 普通地址  1默认地址  2 为删除
    status = models.IntegerField(default=0)

# 指定生成权限
    class Meta:
        permissions = (
            ("show_address", "查看地址管理"),
            ("insert_address", "添加地址"),
            ("edit_address", "修改地址"),
            ("del_address", "删除地址")
        )
# 订单
class Order(models.Model):
    # 用户信息
    uid = models.ForeignKey(to="Users", to_field="id")
    # 地址信息
    aid = models.ForeignKey(to="Address", to_field="id")
    # 总价
    totalprice = models.FloatField()
    # 订单生成时间
    addtime = models.DateTimeField(auto_now_add=True)
   # 状态（0 未付款  1 已付款  2 已收货 3 已取消
    status = models.IntegerField(default=0)

    # 指定生成权限
    class Meta:
        permissions = (
            ("show_order", "查看订单管理"),
            ("insert_order", "添加订单"),
            ("edit_order", "修改订单"),
            ("del_order", "删除订单")
        )

# 订单详情
class OrderInfo(models.Model):
    # 订单id
    orderid = models.ForeignKey(to="Order", to_field="id")
    # 用户id
    goodsid = models.ForeignKey(to="Goods", to_field="id")
    # 商品数量
    num = models.IntegerField()
    # 商品价格
    price = models.FloatField()
